package com.hns.can.mainte.web;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.entity.CommCarChargeInfoEntity;
import com.hns.can.mainte.service.ChargingDetailService;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;

/**
 * 充放电明细Controller 
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/chargingDetail")
public class ChargingDetailController extends BaseController {
	
   final private String[] headerNames = new String[]{"车牌号","运营线路","所属机构","车辆型号","电池材料类型","充电开始时间","充电前SOC值","充电结束时间","充电后SOC值(%)","单次充电时长","总行驶里程","充电前电度表值(kwh)","充电后电度表值(kwh)","充电量(kwh)"};
   final private String[] headerFields = new String[]{"licPltNo","lineName","organName","carType","bteryMaterialType","chargeBeginTime","chargeBeginSocValue","chargeEndTime","chargeEndSocValue","runTime","chargeingTotalMile","chargeBefEltValue","chargeAftEltValue","chargeNum"};
    
    @Autowired
    private ChargingDetailService chargingDetailService;
    @Autowired
    private CommonInitParamService commonInitParamService;
    
    /**
     * 分页查询电池充放电明细数据
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/searchChargingDetail")
	@ResponseBody
    public Object searchChargingDetail(CommonParamsVo params) throws Exception {
    	SysUserEntity user = this.getCurrentUser().getUser();
    	commonInitParamService.initParamsLimitCar(params, user, Arrays.asList("T_COMM_CAR_CHARGE_INFO"));
    	Pagination page = chargingDetailService.searchChargingDetail(params);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 获取充电详情
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/getChargingDetail2")
	@ResponseBody
    public Object searchChargingDetail2(CommonParamsVo params) throws Exception {
    	SysUserEntity user = this.getCurrentUser().getUser();
    	params.setCorpId(user.getCorpId());        
        Pagination page = chargingDetailService.searchChargingDetail2(params);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 导出电池充放电明细Excel文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportChargingDetailExcel")
    public void exportChargingDetailExcel(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<CommCarChargeInfoEntity> list = getChargingDetailData(params,this.getCurrentUser().getUser());
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", "ChargingDetail"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电池充放电明细数据");
    }
    
    /**
     * 导出电池充放电明细Pdf文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportChargingDetailPdf")
    public void exportChargingDetailPdf(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<CommCarChargeInfoEntity> list = getChargingDetailData(params,this.getCurrentUser().getUser());
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", "ChargingDetail"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电池充放电明细数据");
    }    
    
    /**
     * 获取电池充放电明细数据
     * @param params
     * @param user
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    private List<CommCarChargeInfoEntity> getChargingDetailData(CommonParamsVo params, SysUserEntity user ) throws Exception {
        commonInitParamService.initParamsLimitCar(params, user, Arrays.asList("T_COMM_CAR_CHARGE_INFO"));
        List<CommCarChargeInfoEntity> list = chargingDetailService.getChargingDetailData(params);
        return list;
    }
    
}
